package com.example.module_home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.module_base_core.RouteUtils.HomeModuleRoute;
import com.example.module_base_core.net.RestClient;
import com.example.module_base_core.net.callback.IError;
import com.example.module_base_core.net.callback.IFailure;
import com.example.module_base_core.net.callback.ISuccess;
import com.example.module_home.databinding.FragmentHomeBinding;
import com.harisucici.jetpackbase.base.HBaseFragment;

/**
 * @Author : 作者 马坤
 * @Time : On 2020/12/1 14:17
 * @Page: On com.example.module_home
 * @Description : HomeFragment
 */
@Route(path = HomeModuleRoute.Home_Fragment_Main)

public class HomeFragment extends HBaseFragment<FragmentHomeBinding, HomeMode> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_home;
    }


    @Override
    public void initData(View view) {
        super.initData(view);
        binding.btActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "跳转内部的activity", Toast.LENGTH_LONG).show();
                ARouter.getInstance().build(HomeModuleRoute.Home_Activity_test).navigation();
            }
        });

        binding.btExternalActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "跳转外部的activity", Toast.LENGTH_LONG).show();

                ARouter.getInstance().build(HomeModuleRoute.Chat_Activity_test).navigation();
            }
        });
       binding.btNet.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               testNet();
           }
       });

    }

    @Override
    public void initParam() {
        super.initParam();


    }

    @Override
    public int initVariableId() {
        return BR.homemode;
    }


    /**
     * 网络架构的测试
     */
    private void testNet(){
        RestClient.builder().url("https://news.baidu.com").success(new ISuccess() {
            @Override
            public void onSuccess(String response) {
                Toast.makeText(getContext(), response, Toast.LENGTH_LONG).show();
            }
        })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        Toast.makeText(getContext(), msg, Toast.LENGTH_LONG).show();

                    }
                })

                .failure(new IFailure() {
                    @Override
                    public void onFailure() {
                        Toast.makeText(getContext(), "onFailure", Toast.LENGTH_LONG).show();

                    }
                })
                .build().get();
    }

}
